import { ref } from 'vue';
export const useTableRowSelect = () => {
    const selectedRowKeys: any = ref([]);
    const selectedRows: any = ref([]);
    const allSelectedRows: any = ref([]);
    const onSelectChange = (rowKeys: any, rows: any) => {
        console.log('select');
        selectedRowKeys.value = rowKeys;
        selectedRows.value = rows;
        allSelectedRows.value = [...allSelectedRows.value, ...selectedRows.value]; // 将选择的id  进行过滤row  插件只会记录id  不会记录row
        const dealRowArr: any = [];
        if (selectedRowKeys.value.length) {
            selectedRowKeys.value.forEach((id: string) => {
                const target = allSelectedRows.value.find((item) => item.id === id);
                if (target) {
                    dealRowArr.push(target);
                }
            });
        }
        allSelectedRows.value = dealRowArr;
    };
    const setSelectRows = (rowKeys, rows) => {
        selectedRowKeys.value = rowKeys;
        selectedRows.value = rows;
        onSelectChange(selectedRowKeys.value, selectedRows.value);
    };
    const setAllSelectedRows = (rows) => {
        allSelectedRows.value = rows;
    };
    return {
        setSelectRows,
        selectedRowKeys,
        selectedRows,
        allSelectedRows,
        onSelectChange,
        setAllSelectedRows
    };
};